


import allure
import pytest
from selenium.webdriver.common.by import By
from common.DriverTools import DriverTools
from page.admin.AdminGoodsListPage import AdminGoodsListPage
from page.admin.AdminLoginPage import AdminLoginPage
from page.admin.AdminMallPage import AdminMallPage

@allure.feature("商品管理冒烟测试")
class TestAmdinAddGoodSmoke:
    def setup_class(self):
        self.driver = DriverTools.get_driver()
        self.driver.get("http://hmshop-test.itheima.net/admin")
        admin_login = AdminLoginPage(self.driver)
        admin_login.login("admin", "HM_2025_test", 8888)
        self.admin_goods_list = AdminGoodsListPage(self.driver)
        self.admin_mall = AdminMallPage(self.driver)
    def teardown_class(self):
        DriverTools.quit_driver()

    def setup_method(self):
        self.admin_mall.go_to_goods_list()


    # 添加商品成功
    @pytest.mark.smoke
    @allure.title("添加商品冒烟测试")
    def test01_add_goods_success(self):
        good_name = "web测试"
        self.admin_goods_list.add_goods(good_name, "服饰", "女装", "新品推荐", 99, 99, "以件计算")
        self.admin_goods_list.search_goods(good_name)
        result = True
        try:
            self.driver.find_element(By.XPATH, f'//div[normalize-space(text())="{good_name}"]')
        except Exception as e:
            result = False
            print(f"未找到添加的商品名称{good_name}，错误信息{e}")
        assert result == True